var fs = require('fs');
var path = require('path');
function readFileList(dir) {
  const files = fs.readdirSync(dir);
  files.forEach(item => {
    var fullPath = path.join(dir, item);
    const stat = fs.statSync(fullPath);
    if (stat.isDirectory()) {
      readFileList(path.join(dir, item));
    } else {
      const ext = fullPath.split('.')[1]
      if (ext === 'js' || ext === 'vue') {
        var data = fs.readFileSync(fullPath, 'utf-8');
        console.log('当前文件：', fullPath)
        data = data.replace(/(\d+)rem/g, (g, $1) => {
          console.log('=======================')
          console.log('匹配项:', g)
          console.log('替换为:', $1 / 100 + 'rem')
          console.log('=======================')
          return $1 / 100 + 'rem'
        })
        fs.writeFileSync(fullPath, data, 'utf-8')
        console.log(fullPath + '文件替换完毕。。。')
      }
    }
  });
}

readFileList(path.resolve(__dirname, './dir'));